#include "StdAfx.h"
#include "Operand.h"
#include "iCommonActorIterate.h"
#include "Actor.h"

namespace _MODULE_
{
	namespace _GAME_
	{
		Operand::Operand(void)
			:m_ptrGV(NULL)
		{
		}

		Operand::~Operand(void)
		{
		}
		/*virtual*/
		void Operand::Begin()
		{
			i_CommonActorIterate->ReSet();
			

			//check need to advance iter
			if(i_CommonActorIterate->IsReachedEnd()==false&&
				ActorFiter(i_CommonActorIterate->Get()))
			{
				AdvanceActorIter();
			}
			
		}
		/*virtual*/
		bool Operand::Next()
		{
			if(i_CommonActorIterate->IsReachedEnd()==false)
			{
				AdvanceActorIter();
				if(i_CommonActorIterate->IsReachedEnd()==false)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}


		/*virtual*/
		const _FO_GDB::GV* Operand::GetVariable()
		{
			if(i_CommonActorIterate->IsReachedEnd()==false)
			{//retrive gv
				m_ptrGV=i_CommonActorIterate->Get()->FindGV(m_nameData);
				return m_ptrGV;
			}
			else
			{//there is no more actor
				return NULL;
			}

		}

		void Operand::AdvanceActorIter()
		{
			do
			{
				i_CommonActorIterate->Next();
			}
			while(i_CommonActorIterate->IsReachedEnd()==false&&
				ActorFiter(i_CommonActorIterate->Get()));
		}
	}
}